import * as dayjs from 'dayjs'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'
import { initCrisp } from '~/utils'

dayjs.extend(utc)
dayjs.extend(timezone)

export default defineNuxtPlugin((NuxtApp) => {
  const crispInitFn = () => {
    window.removeEventListener('scroll', crispInitFn)
    document.documentElement.removeEventListener('click', crispInitFn)
    initCrisp()
  }
  window.addEventListener('scroll', crispInitFn)
  document.documentElement.addEventListener('click', crispInitFn)
})
